//
//  PBHomeDetailTopCell.m
//  PBHomeDemo
//
//  Created by Playboy on 2017/12/28.
//  Copyright © 2017年 tmkj. All rights reserved.
//

#import "PBHomeDetailTopCell.h"
#import "SXScrPageView.h"
#import "PBHomeTrafficModel.h"

@interface PBHomeDetailTopCell ()
@property (strong, nonatomic) SXScrPageView *pageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *payLabel;
@property (weak, nonatomic) IBOutlet UILabel *bigLabel;
@property (weak, nonatomic) IBOutlet UILabel *secLabel;
@property (weak, nonatomic) IBOutlet UILabel *threeLabel;
@property (weak, nonatomic) IBOutlet UILabel *fourLabel;
@property (weak, nonatomic) IBOutlet UILabel *distanceLabel;


@end

@implementation PBHomeDetailTopCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)refreshWithModel:(PBHomeDetailModel *)model {
    if (!model) {
        return;
    }
    NSMutableArray *imgAry = [[NSMutableArray alloc] init];
    for (PBHomeImageModel *image in model.houseImageList) {
        if (image.url.length > 0) {
            [imgAry addObject:image.url];
        }
    }
    if (!_pageView && imgAry.count > 0) {
        _pageView = [SXScrPageView direcWithtFrame:CGRectMake(15, 10, kScreenWidth-30, 200) ImageArr:imgAry AndImageClickBlock:^(NSInteger index) {
            
        }];
        [_pageView stopTimer];
        [self.contentView addSubview:_pageView];
    }
    self.nameLabel.text = model.name;
    self.typeLabel.text = model.type;
    self.priceLabel.text = [NSString stringWithFormat:@"%@元/月",model.rent];
    self.bigLabel.text = [NSString stringWithFormat:@"%@㎡",model.area];
    self.threeLabel.text = [NSString stringWithFormat:@"%zd/%zd层",model.floor,model.totalFloor];
    if (model.houseTrafficList.count>0) {
        PBHomeTrafficModel *traffic = model.houseTrafficList[0];
        self.distanceLabel.text = traffic.traffic;
    }
    // 朝向 几居室
    [TMNetwork requestGetWithParam:@{@"parentCode":@"House_Orientation"} url:@"/dict/getDictByParentCode" callback:^(TMBaseReqModel *basemodel) {
        for (NSDictionary *dic in basemodel.data) {
            if ([dic[@"code"] integerValue] == model.orientation) {
                self.fourLabel.text = dic[@"name"];
            }
        }
    }];
    [TMNetwork requestGetWithParam:@{@"parentCode":@"House_Room_Num"} url:@"/dict/getDictByParentCode" callback:^(TMBaseReqModel *basemodel) {
        for (NSDictionary *dic in basemodel.data) {
            if ([dic[@"code"] integerValue] == model.roomNum) {
                self.secLabel.text = dic[@"name"];
            }
        }
    }];
}

@end
